<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" isELIgnored="false" %>
  <script type="text/javascript">


      $(function(){
          $("#catalogdatagrid").datagrid({
              url:'${pageContext.request.contextPath}/catalog/findAll',
              pagination:true,
              method:'get',
              fit:true,
              pageSize:5,
              pageList:[5,10,15,20,25],
              fitColumns:true,
              striped:true,
              remoteSort:false,
              checkOnSelect:false,
              toolbar:'#catalogtoolbar',
              onLoadSuccess:function(){
                  $(".btn").linkbutton({
                      plain:true
                  })
              },
              columns:[[
                  {field:'cks',checkbox:true},
                  {title:'场合编号',field:'id',align:'center',width:260},
                  {title:'路径',field:'path',align:'center',width:150},
                  {title:'名称',field:'name',align:'center',width:150},
                  {title:'图片展示',field:'show',align:'center',width:150,formatter:function(index,row,value){
                        return "<img src='${pageContext.request.contextPath}/"+row.path+"?time="+Math.random()+"' style='width:180px;height:80px'>"
                      }},
                  {title:'操作',field:'options',width:300,formatter:function(index,row,value){
                          return "<a href='javascript:;' onclick=\"deleteCatalog('"+row.id+"')\"  class='btn' data-options=\"iconCls:'icon-remove'\">删除</a>&nbsp;&nbsp;" +
                              "<a href='javascript:;' onclick=\"openUpdate('"+row.id+"')\" class='btn' data-options=\"iconCls:'icon-edit'\">更新</a>"

                      }}
              ]]
          })

      });
      //删除场合
      function deleteCatalog(id){
          $.messager.confirm('删除提示','确定要删除吗？？？',function(r){
              if(r){
                  $.post("${pageContext.request.contextPath}/catalog/delete",{"id":id},function(){
                      $("#catalogdatagrid").datagrid('reload');
                  })
              }
          })
      }

      //批量删除
      function deleteSome(){
          var rows=$("#catalogdatagrid").datagrid("getSelections");
          if(rows.length>0){
              $.messager.confirm('删除提示','确定要删除'+rows.length+'条数据吗？？',function(r){
                  if(r){
                      var ids=[];
                      $.each(rows,function(index,row){
                          ids.push(row.id);
                      });
                      $.ajax({
                          url:"${pageContext.request.contextPath}/emp/deleteSome",
                          data:{id:ids},
                          dataType:"JSON",
                          method:'post',
                          traditional:true,
                          success:function(result){
                              $("#userdatagrid").datagrid('reload');
                          }
                      })
                  }
              })
          }else{
              alert("至少选择一项！！");
          }
      }

      //打开添加场合面板
      function openaddCatalog(){
          $("#addCatalogDialog").dialog({
              title:'添加场合信息',
              width:450,
              height:450,
              iconCls:'icon-man',
              href:'${pageContext.request.contextPath}/back/catalog/addCatalog.jsp',
              buttons:[{
                  text:'添加',
                  iconCls:'icon-add',
                  handler:addCatalog
              },{
                  text:'关闭',
                  iconCls:'icon-cancel',
                  handler:function(){
                      $("#addCatalogDialog").dialog('close');
                  }
              }]
          })
      }

      //添加Catalog
      function addCatalog(){
          $("#addCatalogForm").form({
              url:'${pageContext.request.contextPath}/catalog/save',
              onSubmit:function(){
                  return $("#addCatalogForm").form('validate');
              },
              success:function(){
                  $.messager.show({
                      title:'提示信息',
                      msg:'添加成功',
                      timeout:5000,
                      showType:'slide'
                  });
                  $("#addCatalogDialog").dialog('close');
                  $("#catalogdatagrid").datagrid('reload');
              }
          });
          $("#addCatalogForm").form('submit');
      }
      //打开更新窗口
      function openUpdate(id){
          $("#updateCatalogDialog").dialog({
              href:'${pageContext.request.contextPath}/back/catalog/updateCatalog.jsp?id='+id,
              width:450,
              height:450,
              title:'更新场合信息',
              iconCls:'icon-man',
              buttons:[{
                  text:'更新',
                  handler:updateCatalog,
                  iconCls:'icon-save'
              },{
                  text:'关闭',
                  handler:function(){
                      $("#updateCatalogDialog").dialog('close');
                  },
                  iconCls:'icon-cancel'
              }]
          });
      }

      //更新场合信息
      function updateCatalog(){
          $("#updateCatalogForm").form({
              url:'${pageContext.request.contextPath}/catalog/update',
              onSubmit:function(){
                  return $(this).form('validate');
              },
              success:function(result){
                  console.log(result);
                  $.messager.show({
                      title:'提示信息',
                      msg:'更新成功',
                      timeout:5000,
                      showType:'slide'
                  });
                  $("#catalogdatagrid").datagrid('reload');
              },
          });
          $("#updateCatalogForm").form('submit');
          $("#updateCatalogDialog").dialog('close');
      }
  </script>
</head>




<table id="catalogdatagrid" ></table>
<div id="catalogtoolbar">
  <a href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="openaddCatalog();">添加场合</a>
  <a href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="deleteSome();">删除选中</a>
</div>

<div id="addCatalogDialog"></div>
<div id="updateCatalogDialog"></div>

</form>

